<?php
require(dirname(__FILE__)."/../include/config_base.php");
require(dirname(__FILE__)."/../include/inc_channel_unit.php");
if(!isset($action)) $action = "";

if(!empty($aid)) $arcID = $aid;
if(!isset($arcID)) $arcID = 0;
$arcID = ereg_replace("[^0-9]","",$arcID);

if(empty($arcID)){
	  ShowMsg("文档ID不能为空!","-1");
	  exit();
}

//////////////////////////////////////////////
if($action=="")
{
  $dsql = new DedeSql(false);
  //读取文档信息
  $tbs = GetChannelTable($dsql,$arcID,'arc');
  if(!is_array($tbs)){
  	$dsql->Close();
	  ShowMsg("无法获取未知文档的信息!","javascript:;");
	  exit();
  }
  
  $gquery = "Select arc.title,arc.senddate,arc.arcrank,arc.ismake,arc.typeid,arc.channel,arc.money,
  tp.typedir,tp.namerule From `{$tbs['maintable']}` arc left join `#@__arctype` tp on tp.ID=arc.typeid  where arc.ID='$arcID' ";
  $arcRow = $dsql->GetOne($gquery);

  if(is_array($arcRow))
  {
	  $arctitle = $arcRow['title'];
	  $arcurl = GetFileUrl($aid,$arcRow['typeid'],$arcRow['senddate'],$arctitle,$arcRow['ismake'],$arcRow['arcrank'],$arcRow['namerule'],$arcRow['typedir'],$arcRow['money']);
  }else{
	  $dsql->Close();
	  ShowMsg("无法获取未知文档的信息!","javascript:;");
	  exit();
  }
  
  $dsql->Close();
}
//发送推荐信息
//-----------------------------------
else if($action=="send")
{
	if(!eregi("(.*)@(.*)\.(.*)",$email)){
	  echo "<script>alert('Email不正确!');history.go(-1);</script>";
	  exit();
  }
  $mailbody = "";
  $msg = ereg_replace("[><]","",$msg);
  $mailtitle = "你的好友 $name 给你推荐了一篇文章";
  $mailbody .= "$msg \r\n\r\n";
  $mailbody .= "Powered by http://www.dedecms.com 织梦内容管理系统！";
  $mailbody = htmlspecialchars($mailbody);
  if(eregi("(.*)@(.*)\.(.*)",$email))
  {
		$headers = "From: ".$cfg_adminemail."\r\nReply-To: ".$cfg_adminemail;
		sendmail($email, $mailtitle, $mailbody, $headers);
  }
  ShowMsg("成功推荐一篇文章!",$arcurl);
  exit();
}

//显示模板(简单PHP文件)
include_once($cfg_basedir.$cfg_templets_dir."/plus/recommend.htm");
?>
